<template>
	<view>
		<view class="authorizationPopup" @click="getUserProfile"></view>
		<button type="primary" class='btn' open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" v-if="!phone"></button>
		
	</view>	
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				phone:''
			};
		},
		onLoad(e) {


		},
		onShow() {

		},
		mounted() {
			this.phone=uni.getStorageSync('phone')
		},

		methods: {
			getPhoneNumber(e) {
				console.log("获取手机号码",e.detail)
				if (e.detail.errMsg !== 'getPhoneNumber:ok') {
					this.$u.toast("拒绝手机号登录");
					return;
				}
				uni.showLoading()
				this.$http
					.getphone({
						code: e.detail.code
			
					})
					.then(res => {
						uni.setStorageSync('phone',res.data)
						this.phone=res.data
						console.log(res)
			
			
					})
			
			
			
			
			},
			getUserProfile(e) {
				var self = this;
				uni.getUserProfile({
					desc: '获取用户信息',
					success: (info) => {

						wx.login({
							success: (res) => {
								self.userLogin(res.code)
							}
						})
					}
				})
			},

			userLogin(code) {

				this.$http
					.userLogin({
						code: code,
						phone:this.phone

					})
					.then(res => {
						if (res.code == 0) {
							uni.setStorageSync('token', res.data)
							this.$emit('updateFn')
						}

					})
			},

		}
	};
</script>

<style scoped lang="scss">
	.btn{
		position: fixed;
		top: 0;
		left: 0;
		background: transparent;
		width: 100%;
		height: 100%;
		z-index: 10000002;
		opacity: 0;
	}
	.authorizationPopup {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: 10000001;

	
	}
</style>
